#pragma once

#include "AbstractRequestHandler.h"
#include "RequestHandlerDefinition.h"
#include "Poco/Net/HTTPServerRequest.h"
#include "Poco/Logger.h"
#include "Poco/Net/HTTPRequestHandlerFactory.h"
#include "Poco/ClassLoader.h"

#include <vector>

class RequestHandlerFactory : public Poco::Net::HTTPRequestHandlerFactory
{
public:
	RequestHandlerFactory();
	~RequestHandlerFactory();

	Poco::Net::HTTPRequestHandler * createRequestHandler(const Poco::Net::HTTPServerRequest& request);

	void setRequestHandler(std::vector<RequestHandlerDefinition>& src) {
		_requestHandlers = src;
	}

private:
	bool loadAllLibraries();
	bool loadLibrary(std::string libraryName);
private:
	Poco::Logger &_log = Poco::Logger::get("RequestHandlerFactory");
	Poco::ClassLoader<AbstractRequestHandler> _classLoader;
	std::vector<RequestHandlerDefinition> _requestHandlers;
};

